﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LiteratureManage.Domain.DataBackup
{
    public abstract class DBTableBackup
    {
        private readonly string _dbTable;
        private readonly IDBTableBackupExecutor _backupExecutor;
        public int BackupOrder { get; set; }
        public int RestoreOrder { get; set; }
        public int ResetOrder { get; set; }

        public DBTableBackup(string dbTable, IDBTableBackupExecutor backupExecutor)
        {
            this._dbTable = dbTable;
            this._backupExecutor = backupExecutor;
        }

        public void Backup(DateTime theDate, string backupDirPath)
        {
            var queryText = this.BuildQueryText(theDate);
            var backupFilePath = Path.Combine(backupDirPath, this._dbTable);
            this._backupExecutor.PostBackup(queryText, backupFilePath);
        }

        public void Restore(string backupDirPath)
        {
            var backupFilePath = Path.Combine(backupDirPath, this._dbTable);
            this._backupExecutor.PostRestore(this._dbTable, backupFilePath);
        }

        public void Reset()
        {
            this._backupExecutor.PostReset(this._dbTable);
        }

        protected abstract string BuildQueryText(DateTime theDate);
    }
}
